package com.xzan.medusa.core;

import com.xzan.medusa.common.util.http.HttpsClientUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

@Slf4j
public class StockUtil {
    private final static String SINA_URL = "http://hq.sinajs.cn/list=";

    public static String getStockName(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }
        if (code.startsWith("30") || code.startsWith("00")) {
            code = "sz" + code;
        } else {
            code = "sh" + code;
        }
        String executeUrl = SINA_URL + code;
        String content = HttpsClientUtils.get(executeUrl);
        String[] contents = content.split("\"");
        String name = contents[1].split(",")[0];
        log.info("{}", name);
        return name;
    }

    public static void main(String[] args) {
        StockUtil.getStockName("00jdfdf");
    }


}
